#!/bin/sh /etc/rc.common
# Copyright (C) 2017 OpenWrt.org

USE_PROCD=1

START=90
STOP=10

PROG=/usr/sbin/i2pd
USER="i2pd"
GROUP="i2pd"
PIDFILE=/var/run/i2pd.pid
DATADIR=/etc/i2pd
PEERDIR=/var/lib/i2pd/peerProfiles


start_service() {
	## RAM
	if [ ! -d $PEERDIR ]; then
		mkdir -p $PEERDIR
		chown $USER:$GROUP $PEERDIR
	fi

	## We need permissions
	chown -R $USER:$GROUP $DATADIR
	touch $PIDFILE
	chown $USER:adm $PIDFILE

	procd_open_instance
	procd_set_param command $PROG --service --conf=/etc/i2pd/i2pd.conf
	## Don't know about i2pd user's HOME
	procd_set_param env HOME=$DATADIR
	procd_set_param limits nofile=4096
	procd_set_param stdout 1
	procd_set_param stderr 1
	procd_set_param user $USER
	procd_set_param pidfile $PIDFILE
	procd_close_instance
}
